#!/bin/bash
#
# $Id: unihan-client,v 1.4 2002/09/03 13:08:44 rogerso Exp $
#
# This is the wrapper that makes loading the Unihan client a bit easier.

PATH=/usr/lib/im:$PATH
export PATH

HTT_BRIDGE=/usr/lib/im/httx
LEIF=unihan2

if [ ! -x "$HTT_BRIDGE" ]; then
  echo "ERROR: Cannot find the IIIM-XIM bridge, which should be at "
  echo "\t$HTT_BRIDGE"
  echo "It is needed to provide the Unihan client."
  exit 1
fi

LOCALE=/usr/bin/locale
GREP=/bin/grep
SED=/bin/sed

lc_ctype=`$LOCALE | $GREP LC_CTYPE | $SED s/^LC_CTYPE=// | $SED s/\"//g`
charmap=`$LOCALE -k charmap | $SED s/^charmap=// | $SED s/\"//g`
if [ "$charmap" = "ANSI_X3.4-1968" ]; then
  /bin/cat <<GLIBC_NO_LOCALE
ERROR: The C library says you are using the $charmap character set, 
       which does not have Chinese characters. Please ensure you are
       using a correct Chinese locale before you start Unihan.
GLIBC_NO_LOCALE
  exit 1
fi

if [ -z "`$GREP $lc_ctype /usr/X11R6/lib/X11/locale/locale.dir`" ]; then
  if [ -z "`$GREP $lc_ctype /usr/X11R6/lib/X11/locale/locale.alias`" ]; then
    /bin/cat <<X_NO_LOCALE
ERROR: XFree86 does not have information about the locale you specified
       ($lc_ctype)
X_NO_LOCALE
    exit 1
  fi
fi

# Finally!!!
echo -n "Starting Unihan client for $charmap..."
GDK_USE_XFT=1 $HTT_BRIDGE -if $LEIF &
echo ""

sleep 5s

exec "$@"
